<?
/****************************************/
/************* IdeaLAN LLC **************/
/* Auto Fill used to load customers     */
/* From the databse in to form fields.  */
/*                                      */
/****************************************/
/****************************************/
/* SCRIPT: autofill.php     VER: 1.1    */
/* AUTHOR: Lukasz Piekarski             */
/* E-mail: lukasz@idealan.net           */
/* UPDATE: 7.13.11						*/
/****************************************/
/*
TODO +
	 -
END TODO
*/
$config_path = "../../";
$cFile = $config_path . "addons/config.ini";

include ($config_path . "config.php");

if(isset($_GET['getCountriesByLetters']) && isset($_GET['letters'])) {
	// START SEARCH
	
	$letters = $_GET['letters'];
	$letters = preg_replace("/[^a-z0-9 ]/si","",$letters);

	$resFname = mysql_query("SELECT * FROM `".$DBprefix."customers` WHERE `cust_fname` LIKE '".$letters."%'") or die(mysql_error());
	$num_Fnames = mysql_num_rows($resFname);

	$resLname = mysql_query("SELECT * FROM `".$DBprefix."customers` WHERE `cust_lname` LIKE '".$letters."%'") or die(mysql_error());
	$num_Lnames = mysql_num_rows($resLname);


	if ($num_Fnames >= 0) {
		// SEARCH FIRST NAMES
	
		while($inf = mysql_fetch_array($resFname)){
			echo $inf["cust_id"]."###".$inf["cust_fname"]." ".$inf["cust_lname"]." - ".$inf["cust_city"]."|";

			$sqFn = $inf["cust_id"]."###".$inf["cust_fname"]." ".$inf["cust_lname"]." - ".$inf["cust_city"]."|";
		}	
	} // END SEARCH FIRST NAMES

	if ($num_Lnames >= 0) {
		// SEARCH LAST NAMES

		while($infL = mysql_fetch_array($resLname)){
		
			$sqLn = $infL["cust_id"]."###".$infL["cust_fname"]." ".$infL["cust_lname"]." - ".$infL["cust_city"]."|";
		
			if ($sqFn != $sqLn) { 
				echo $infL["cust_id"]."###".$infL["cust_fname"]." ".$infL["cust_lname"]." - ".$infL["cust_city"]."|";
			}
		}	
	} // SEARCH LAST NAMES

} // END SEARCH



?>
